package com.css.landslide.risk.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.css.landslide.risk.entity.LandslideRiskRaster;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author Dbj
 * @date 2025年02月13日  15:38
 */
@Mapper
public interface LandslideRiskRasterMapper extends BaseMapper<LandslideRiskRaster> {
    @Select("with sjz AS (SELECT ST_GeomFromText(#{geom}, 4490) AS geom),nodata AS (SELECT ST_BandNoDataValue(geom) AS nodata_value " +
            "  FROM data_landslide_risk_raster LIMIT 1) " +
            " SELECT (p).val AS value,(p).geom intersectGeom" +
            " FROM (select * from data_landslide_risk_raster where id>=#{start} and id<=#{end}) r " +
            "JOIN sjz s ON ST_Intersects(r.geom, s.geom) " +
            "CROSS JOIN LATERAL ST_PixelAsPolygons(ST_Clip(r.geom, s.geom)) AS p " +
            "JOIN nodata n ON (p).val != n.nodata_value ")
    List<LandslideRiskRaster> selectRiskLandslide(@Param("geom") String geom, @Param("start")int start, @Param("end")int end);
}
